# -*- coding: utf-8 -*-
#高级特性----切片  对list、str都可以

import io
import sys
sys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding='utf-8')

L=['a','b','c','d']

print(L[:])
print(L[:4])
print(L[-4:])
print(L[0:4])
print(L[0:3])
print(L[-4:-1])
print(L[-3:-2])

# ['a', 'b', 'c', 'd']
# ['a', 'b', 'c', 'd']
# ['a', 'b', 'c', 'd']
# ['a', 'b', 'c', 'd']
# ['a', 'b', 'c']
# ['a', 'b', 'c']
# ['b']


# 实现trim() 函数
def trim(str):
	if(len(str)==0):
		return ''
	if(str[0] == ' '):
		return trim(str[1:])
	if(str[-1] == ' '):
		return trim(str[:len(str)-1])
	return str

if trim('hello  ') != 'hello':
    print('测试失败!')
elif trim('  hello') != 'hello':
    print('测试失败!')
elif trim('  hello  ') != 'hello':
    print('测试失败!')
elif trim('  hello  world  ') != 'hello  world':
    print('测试失败!')
elif trim('') != '':
    print('测试失败!')
elif trim('    ') != '':
    print('测试失败!')
else:
    print('测试成功!')